package emap;

//AXED!

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.ImageObserver;
import java.awt.image.FilteredImageSource;
import java.awt.image.CropImageFilter;
import java.awt.image.BufferedImage;
import java.awt.image.RescaleOp;

class Viewport 
{
	private Graphics2D drawingUnit;
	private Rect drawingRect; //signifies where to draw to. Used when setDrawTo is called
	private Rect viewingRect; //signifies what the view is viewing.
	private Rect movingLimits; //Take the limit of integral(1,a,1/x,x) as a->infinity is INFINITY!!!
	
	//constructors
	public Viewport()
	{
		drawingRect=new Rect();
		viewingRect=new Rect();
		movingLimits=new Rect();
	}
	public Viewport(int x,int y,int w,int h,int mx,int my)
	{
		drawingRect=new Rect(x,y,x+w,y+h);
		viewingRect=new Rect(0,0,w,h);
		movingLimits=new Rect(0,0,mx,my);
	}
	public Viewport(int x,int y,int w,int h,Coord movLim)
	{
		drawingRect=new Rect(x,y,x+w,y+h);
		viewingRect=new Rect(0,0,w,h);
		movingLimits=new Rect(0,0,movLim.X,movLim.Y);
	}
	//sets drawing unit. AKA the space the viewport has to draw on.
	public void setDrawTo(Graphics2D ng)
	{
		drawingRect.clean();
		//drawingUnit=(Graphics2D)ng.create(drawingRect.X1,drawingRect.Y1,drawingRect.X2,drawingRect.Y2);
		drawingUnit=(Graphics2D)ng.create(drawingRect.X1,drawingRect.Y1,drawingRect.X2-drawingRect.X1,drawingRect.Y2-drawingRect.Y1);
	}

	public Graphics2D getGraphics()
	{
		return drawingUnit;
	}
	public void setDrawingRect(Rect a){
		drawingRect=new Rect(a);
	}
	public Rect getDrawingRect(){
		return new Rect(drawingRect);
	}
	public void setViewingRect(Rect a){
		viewingRect=new Rect(a);
	}
	public Rect getViewingRect(){
		return new Rect(viewingRect);
	}
	public void setMovingLimits(Rect a){
		movingLimits=new Rect(a);
	}
	public Rect getMovingLimits(){
		return new Rect(movingLimits);
	}
	private int offX(int nx){return nx-viewingRect.X1;}
	private int offY(int ny){return ny-viewingRect.Y1;}
	public void drawImage(Image whattodraw,int xPosition,int yPosition)
	{
		drawingUnit.drawImage(whattodraw,offX(xPosition),offY(yPosition),null);
	}
	public void drawImage(Image whattodraw,Coord Position){
		drawImage(whattodraw,Position.X,Position.Y);
	}
	public void scroll(int xScroll,int yScroll){
		viewingRect.scroll(xScroll,yScroll);
		viewingRect.moveInside(movingLimits);
	}
	public void centerOn(int x,int y){
		viewingRect.centerOn(x,y);
		viewingRect.moveInside(movingLimits);
	}
}